package com.etheart.music.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.etheart.framework.core.dao.CrudService;
import com.etheart.framework.core.dao.QueryService;
import com.etheart.model.entity.Album;

@Service("music_AlbumService")
public class AlbumServiceImp implements AlbumService {
	@Autowired
	@Qualifier("etheart_QueryService")
	private QueryService queryService;

	@Autowired
	@Qualifier("etheart_CrudService")
	private CrudService crudService;
	
	/* (non-Javadoc)
	 * @see com.etheart.lyric.music.service.AlbumService#findAll()
	 */
	@Override
	public List<Album> findAll(){
		return queryService.findAll(Album.class);
	}
	
	/* (non-Javadoc)
	 * @see com.etheart.lyric.music.service.AlbumService#addAlbum(com.etheart.module.entity.Album)
	 */
	@Override
	@Transactional
	public void addAlbum(Album album){
		crudService.create(album);
	}
	/* (non-Javadoc)
	 * @see com.etheart.lyric.music.service.AlbumService#updateAlbum(com.etheart.module.entity.Album)
	 */
	@Override
	@Transactional
	public void updateAlbum(Album album){
		crudService.update(album);
	}
	
	/* (non-Javadoc)
	 * @see com.etheart.lyric.music.service.AlbumService#deleteAlbum(com.etheart.module.entity.Album)
	 */
	@Override
	@Transactional
	public void deleteAlbum(Album album){
		crudService.delete(album);
	}

	@Override
	public Album findById(long albumId) {
		return queryService.findById(Album.class, albumId);
	}

	@Override
	public Album findByNetId(String albumNetId) {
		Album album =new Album();
		album.setNetId(albumNetId+"");
		List<Album> albums=queryService.findByExample(album);
		if (albums.size()>0) {
			return albums.get(0);
		}
		return null;
	}

	public Album findByFormUrl(String fromUrl) {
		Album album = new Album();
		//album.setFromUrl(fromUrl);
		List<Album> albums=queryService.findByExample(album);
		if (albums.size()>0) {
			return albums.get(0);
		}
		return null;
	}
	
	
}
